import javax.swing.plaf.metal.MetalIconFactory;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 马拉圈
 * Date: 2023-03-19
 * Time: 8:03
 */
public class Tres {

    public static void create(Thread[] threads, int index) {
        threads[index] = new Thread(() -> {
            while(!Thread.currentThread().isInterrupted()) {
                System.out.println(index);
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                    break;
                }
            }

        });
    }
    public static void main1(String[] args) throws InterruptedException {
        Thread[] threads = new Thread[20];
        for (int j = 0; j < 20; j++) {
            create(threads, j);
            threads[j].start();
        }
        Thread.sleep(3000);
        for (int i = 0; i < 20; i++) {
            threads[i].interrupt();
        }
        System.out.println("ok");
    }
}
